import React, { useEffect, useRef } from 'react'

function uselodash(fun, time) {
    let dsq=useRef()
    useEffect(() => {
        return () => {
            if (dsq.current) {
                clearTimeout(dsq.current)
            }
        }
    }, [])
    return (...val) => {
       
        if (dsq.current) {
            clearTimeout(dsq.current)
        }
        dsq.current = setTimeout(() => {
            fun(...val)
        }, time)
    }
}

export default uselodash
